package com.czl.module_service.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.ApproveBean
import com.czl.base.data.bean.tengyun.AssetHandleBean
import com.czl.base.data.bean.tengyun.ProcessStatusList
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemAssetHandleApprovalListBinding
import com.czl.module_service.fragment.assetHandle.AssetHandleApprovalListFragment

class AssetHandleApprovalListAdapter(private val fragment: AssetHandleApprovalListFragment) :
    BaseQuickAdapter<ApproveBean, BaseDataBindingHolder<ItemAssetHandleApprovalListBinding>>(
        R.layout.item_asset_handle_approval_list
    ) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemAssetHandleApprovalListBinding>,
        item: ApproveBean,
    ) {
        holder.dataBinding?.run {
            item.submitDateStr = item.submitDateToStr(item.submitDate)
            data = item
            adapter = this@AssetHandleApprovalListAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is ApproveBean) {
            var taskUserId:String? = ""
            if (it.processStatus == 1 && it.taskUserId != null && it.taskUserId!!.isNotEmpty() && it.status == 2) {
                taskUserId = it.taskUserId
            }
            fragment.startContainerActivity(
                AppConstants.Router.Service.F_SERVICE_ASSET_HANDLE_APPLY_INFO,
                Bundle().apply {
                    putSerializable("handleApplicationId", it.relationId!!.toInt())
                    putSerializable("taskUserId", taskUserId)
                })
        }
    })
}
